<?php
namespace Admin\Controller;
use Common\Controller\CommonController;
class AdminController extends CommonController{
	protected $username;
	
	public function _initialize(){
		parent::_initialize();
		if(!session('?user')){
			$this->redirect('Login/showLogin');
		}	
	}

	////图片处理
	public function upload($file){
          ///判断是否是图片类型
	      switch($file['type'])
		    {
		        case 'image/jpeg': $ext = 'jpg'; break;
		        case 'image/gif': $ext = 'gif'; break;
		        case 'image/png': $ext = 'png'; break;
		        case 'image/tiff': $ext = 'tif'; break;
		        default: $ext = ''; break;
		    }
		    if (empty($ext)){
		        $this -> error('不支持的图片格式');
		    }
	        $upload = new \Think\Upload();// 实例化上传类    
	        $upload ->maxSize   =  9999999999 ;// 设置附件上传大小    
	        $upload ->exts      =  array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
	        $upload ->savePath  =  '/'; // 设置附件上传目录    // 上传单个文件
	        $upload ->saveName  =  rand(1000,9999).time(); 
	        $info   =   $upload->uploadOne($file);
	        if(!$info) {// 上传错误提示错误信息        
	          $this ->error($upload->getError());    
	        }else{
	        	$pic=$info['savepath'].$info['savename'];
			    $url='/Uploads'.ltrim($pic,".");
			    return $url;
	        }
	}

}